package com.qf.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.qf.feign.TestProviderFeign;
import com.qf.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author:z
 * time:2022/1/6 11:15
 * description:
 */
@RestController
@RequestMapping("/consumer")
//动态刷新从配置文件获取的内容
@RefreshScope
@Api(description = "消费者接口")
public class ConsumerController {
    @Autowired
    private TestProviderFeign testProviderFeign;

    //从nacos的配置中心当中, 找到key为version的内容, 获取值给下面变量赋值
    @Value("${version}")
    private String version;

    @GetMapping("/test1")
    @ApiOperation(value = "测试1")
    public String test1(){
        String str = testProviderFeign.test1();
        return str+"======================"+version;
    }

    @GetMapping("/test2")
    @SentinelResource("/xxx")
    @ApiOperation(value = "测试2")
    public String test2(String s,String ss){
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "测试熔断降级";
    }

    @GetMapping("/user")
    @ApiOperation(value = "查询用户实体类")
    public User findUser(){
        User user=new User();
        user.setId(11L);
        user.setName("法外狂徒马英凯");
        return  user;
    }
}
